﻿/*
 * Created by SharpDevelop.
 * User: cszhangyi
 * Date: 2016/4/8
 * Time: 16:10
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

using Newtonsoft.Json;
using YMTSeller.Model;

namespace YMTSeller
{
	/// <summary>
	/// Description of LoginHandle.
	/// </summary>
	public class LoginHandler
	{
		private string username;
		private string password;
		
		public LoginHandler(string username, string password)
		{
			this.username = username;
			this.password = password;
		}
		
		public Dictionary<string, string> login()
		{
			string url = "http://seller.app.ymatou.com/api/v1_1/AuthSeller";
			
			LoginRequestModel requestModel = new LoginRequestModel();
			
			requestModel.AppName = "Seller";
			requestModel.ClientType = 1;
			requestModel.DeviceToken = "623ee5d7e41fd73213df948b9cafa924d4dedc32375a06af7c02eb37c03d5893";
			requestModel.Guid = "5F58DCEF-D449-46FF-81EF-02B569B9B260";
			requestModel.LoginType = 0;
			requestModel.Password = this.password;
			requestModel.Username = this.username;
			requestModel.Wifi = 0;
			requestModel.App = "seller";
			requestModel.Os = "iPhone8,4";
			requestModel.Sys = "9.3";
			requestModel.Version = "2.5.1";
			
			string paramData = requestModel.toString();
			
			YMTRequest request = new YMTRequest();
			string val = request.post(url, paramData, System.Text.Encoding.GetEncoding("utf-8"));
			
			LoginResponseModel responseModel = (LoginResponseModel) JsonConvert.DeserializeObject(val, typeof(LoginResponseModel));
			
			Dictionary<string, string> result = new Dictionary<string, string>();
			result.Add("Msg", responseModel.Msg);
			result.Add("Status", responseModel.Status.ToString());
			
			if (responseModel.Result != null)
			{
				result.Add("AccessToken", responseModel.Result.AccessToken);
				result.Add("UserId", responseModel.Result.UserId.ToString());
			}
			
			return result;
		}
	}
}
